using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.Regions;
using Microsoft.Practices.Unity;
using Navigator.ViewModel;
using Navigator.Interfaces;

namespace Navigator
{
    [Module(ModuleName = "Navigator")]
    public class NavigatorModule:IModule
    {
        private readonly IUnityContainer m_Container;
        private readonly IRegionManager m_RegionManager;

        public NavigatorModule(IUnityContainer m_Container, IRegionManager m_RegionManager)
        {
            this.m_Container = m_Container;
            this.m_RegionManager = m_RegionManager;
        }

        public void Initialize()
        {
            RegisterViewAndServices();
            var narvigatorView = new NavigatorView();
            narvigatorView.DataContext= m_Container.Resolve<INavigatorViewModel>();
            m_RegionManager.Regions["NavigatorRegion"].Add(narvigatorView);
        }

        private void RegisterViewAndServices()
        {
            m_Container.RegisterType<INavigatorViewModel, NavigatorViewModel>();
        }
    }
}